using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc;
using MultilingualLocalization.Models;
using System.Diagnostics;
using System.Globalization;

namespace MultilingualLocalization.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;

        public HomeController(ILogger<HomeController> logger)
        {
            _logger = logger;
        }

        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="culture"></param>
        /// <param name="returnUrl"></param>
        /// <returns></returns>
        public ActionResult ChangeLanguage(string culture, string returnUrl)
        {
            var cultureInfo = new CultureInfo(culture);
            var requestCulture = new RequestCulture(cultureInfo);
            Response.Cookies.Append(
            CookieRequestCultureProvider.DefaultCookieName,
            CookieRequestCultureProvider.MakeCookieValue(requestCulture));
            //Response.Cookies.Append(
            //CookieRequestCultureProvider.DefaultCookieName,
            //CookieRequestCultureProvider.MakeCookieValue(requestCulture),
            //new CookieOptions { Expires = DateTimeOffset.UtcNow.AddYears(1) }
            // );

            return RedirectToAction("Index", "Home");
        }
    }
}
